use crate::services::workflow::{run_by_identifier, RunArguments};
use actix_web::{error, get, post, web, Error, HttpRequest, HttpResponse};
use serde_json::json;

#[post("/workflow/run/{identifier}")]
pub async fn workflow_run_by_identifier(
    data: web::Data<crate::AppState>,
    identifier_param: web::Path<String>,
    request_obj: web::Json<RunArguments>,
    req: HttpRequest,
) -> Result<HttpResponse, Error> {
    //用户ID
    // let user_id = crate::services::get_user_id(&req)?;
    //
    let identifier = identifier_param.into_inner();
    let update_obj = request_obj.into_inner();

    let res = run_by_identifier(&identifier, update_obj)
        .await
        .map_err(|err| error::ErrorInternalServerError(err))?;

    Ok(HttpResponse::Ok().json(json!(res)))
}
